package thread;

/**
 * Created with IntelliJ IDEA.
 *
 * @ Title
 * @ Description:
 * @ Auther: 赵彦博
 * @ Date: 2022-12-02
 * @ Time: 18:56
 */
@SuppressWarnings({"all"})
public class Demo11 {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("这是收尾工作");
                    break;
                }
            }
        });
        t.start();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 在主线程中， 调用interrupt 方法，来中断这个线程
        t.interrupt();
    }
}
